﻿Imports Microsoft.VisualBasic
Imports System.Data

Public Class task

#Region "Properties"

	Private _taskId As Integer
	Public Property TaskId() As Integer
		Get
			Return _taskId
		End Get
		Set(ByVal value As Integer)
			_taskId = value
		End Set
	End Property

	Private _taskName As String
	Public Property TaskName() As String
		Get
			Return _taskName
		End Get
		Set(ByVal value As String)
			_taskName = value
		End Set
	End Property

	Private _taskDesc As String
	Public Property TaskDesc() As String
		Get
			Return _taskDesc
		End Get
		Set(ByVal value As String)
			_taskDesc = value
		End Set
	End Property

	Private _featureID As Integer
	Public Property FeatureID() As Integer
		Get
			Return _featureID
		End Get
		Set(ByVal value As Integer)
			_featureID = value
		End Set
	End Property

	Private _statusID As Integer
	Public Property StatusID() As Integer
		Get
			Return _statusID
		End Get
		Set(ByVal value As Integer)
			_statusID = value
		End Set
	End Property

	Private _priorityID As Integer
	Public Property PriorityID() As Integer
		Get
			Return _priorityID
		End Get
		Set(ByVal value As Integer)
			_priorityID = value
		End Set
	End Property

	Private _estTime As Integer
	Public Property EstimatedTime() As Integer
		Get
			Return _estTime
		End Get
		Set(ByVal value As Integer)
			_estTime = value
		End Set
	End Property

	Private _actTime As Integer
	Public Property ActualTime() As Integer
		Get
			Return _actTime
		End Get
		Set(ByVal value As Integer)
			_actTime = value
		End Set
	End Property

	Private _userID As String
	Public Property UserID() As String
		Get
			Return _userID
		End Get
		Set(ByVal value As String)
			_userID = value
		End Set
	End Property

#End Region

#Region "Constructors"

	Public Sub New()
	End Sub

	Public Sub New(ByVal iTaskId As Integer)
		Me.TaskId = iTaskId
		Me.GetTaskDetails()
	End Sub

#End Region

#Region "Methods"

	Dim _dal As New ScrumrData

	Public Sub AddTask(ByVal iFeatureID As Integer, ByVal sTaskName As String, ByVal sTaskDesc As String, ByVal iPriorityID As Integer, ByVal iEstTime As Integer, ByVal sUserID As String)

		Me.FeatureID = iFeatureID
		Me.TaskName = sTaskName
		Me.TaskDesc = sTaskDesc
		Me.PriorityID = iPriorityID
		Me.EstimatedTime = iEstTime
		Me.UserID = sUserID

		Try
			Me.TaskId = _dal.SaveTask(Me.FeatureID, Me.TaskName, Me.TaskDesc, Me.PriorityID, _
			  Me.EstimatedTime, Me.UserID)
		Catch ex As Exception
			Throw New Exception("Business layer error: " & ex.Message)
		End Try

	End Sub

	Public Sub AssignTaskToUser(ByVal sUserID As String, ByVal iTaskID As Integer)
		_dal.AssignTaskToUser(sUserID, iTaskID)
	End Sub

	Public Sub GetTaskDetails()
		Dim _ds As DataSet

		_ds = _dal.GetTaskDetails(Me.TaskId)

		Me.FeatureID = _ds.Tables(0).Rows(0).Item("featureId")
		Me.TaskName = _ds.Tables(0).Rows(0).Item("taskName")
		Me.TaskDesc = _ds.Tables(0).Rows(0).Item("taskDesc")
		Me.StatusID = _ds.Tables(0).Rows(0).Item("statusId")
		Me.PriorityID = _ds.Tables(0).Rows(0).Item("priorityId")
		Me.EstimatedTime = _ds.Tables(0).Rows(0).Item("taskEstimatedTime")
		Me.ActualTime = _ds.Tables(0).Rows(0).Item("taskActualTime")

	End Sub

	Public Sub UpdateTask()

		Try
			_dal.UpdateTask(Me.TaskId, Me.TaskName, Me.TaskDesc, Me.StatusID, Me.PriorityID, Me.EstimatedTime, Me.ActualTime, Me.UserID)
		Catch ex As Exception
			Throw New Exception("Business layer error: " & ex.Message)
		End Try

	End Sub

#End Region

End Class
